package com.hb.podao;

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.hibernate.Query;
import org.hibernate.criterion.Example;

import com.core.BaseHibernateDAO;
/**
 * Data access object (DAO) for domain model class HbDraw.
 * 
 * @see com.hb.podao.HbDraw
 * @author MyEclipse Persistence Tools
 */

public class HbDrawDAO extends BaseHibernateDAO {
	private static final Log log = LogFactory.getLog(HbDrawDAO.class);

	// property constants
	public static final String USERID = "userid";

	public static final String BANK = "bank";

	public static final String ACCOUNT = "account";

	public static final String COST = "cost";

	public static final String STATUS = "status";

	public static final String CHECKID = "checkid";

	public static final String REMARK = "remark";

	public void save(HbDraw transientInstance) {
		log.debug("saving HbDraw instance");
		try {
			getSession().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(HbDraw persistentInstance) {
		log.debug("deleting HbDraw instance");
		try {
			getSession().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public HbDraw findById(java.lang.Integer id) {
		log.debug("getting HbDraw instance with id: " + id);
		try {
			HbDraw instance = (HbDraw) getSession().get("com.hb.podao.HbDraw",
					id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List findByExample(HbDraw instance) {
		log.debug("finding HbDraw instance by example");
		try {
			List results = getSession().createCriteria("com.hb.podao.HbDraw")
					.add(Example.create(instance)).list();
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding HbDraw instance with property: " + propertyName
				+ ", value: " + value);
		try {
			String queryString = "from HbDraw as model where model."
					+ propertyName + "= ?";
			Query queryObject = getSession().createQuery(queryString);
			queryObject.setParameter(0, value);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List findByUserid(Object userid) {
		return findByProperty(USERID, userid);
	}

	public List findByBank(Object bank) {
		return findByProperty(BANK, bank);
	}

	public List findByAccount(Object account) {
		return findByProperty(ACCOUNT, account);
	}

	public List findByCost(Object cost) {
		return findByProperty(COST, cost);
	}

	public List findByStatus(Object status) {
		return findByProperty(STATUS, status);
	}

	public List findByCheckid(Object checkid) {
		return findByProperty(CHECKID, checkid);
	}

	public List findByRemark(Object remark) {
		return findByProperty(REMARK, remark);
	}

	public List findAll() {
		log.debug("finding all HbDraw instances");
		try {
			String queryString = "from HbDraw";
			Query queryObject = getSession().createQuery(queryString);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public HbDraw merge(HbDraw detachedInstance) {
		log.debug("merging HbDraw instance");
		try {
			HbDraw result = (HbDraw) getSession().merge(detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(HbDraw instance) {
		log.debug("attaching dirty HbDraw instance");
		try {
			getSession().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(HbDraw instance) {
		log.debug("attaching clean HbDraw instance");
		try {
			getSession().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}
}